package com.game.config.dao;

import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty;
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceProperties;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

@Component
public class JdbcUtils {
    @Resource
    private Environment environment;
    @Resource
    private DynamicDataSourceProperties dynamicDataSourceProperties;

    public Map<String, DataSourceProperty> getDataSourceProperty() {
        // 获取多数据数据原配置
        //
        // String url = environment.getProperty("spring.datasource.druid.url");
        // String username = environment.getProperty("spring.datasource.druid.username");
        // String password = environment.getProperty("spring.datasource.druid.password");
        // assert url != null;
        // String[] split = url.split(":");
        // String host = String.format("%s:%s:%s", split[0], split[1], split[2]);
        // String[] portSplit = split[3].split("/");
        // String port = portSplit[0];
        //
        // String[] databaseSplit = portSplit[1].split("\\?");
        // String dbName = databaseSplit[0];
        // HashMap<String, String> result = new HashMap<>();
        // result.put("url",url);
        // result.put("host",host);
        // result.put("port",port);
        // result.put("dbName",dbName);
        // result.put("userName",username);
        // result.put("passWord",password);

        return dynamicDataSourceProperties.getDatasource();
    }
}

